'use strict';
angular.module('sbAdminApp')
    .controller('StatisticaorderCtrl', ['$scope','$modal','$log','$location','statisticaorderService',function ($scope, $modal, $log, $location, statisticaorderService) {
        //初始化作用域变量
        $scope.lists = [];
        $scope.totalItems = 0;
        $scope.currentPage = 1;
        $scope.itempersize = 10;
        
        //切换分页事件时触发方法
        $scope.pageChanged = function () {
        	 $scope.search1();
        };
        
        //点击查询触发
        $scope.search1 = function () {
        	var begin = $("#beginDate").val(); 
        	var end = $("#endDate").val();
        	
        	statisticaorderService.search1($scope.sorder,
        			begin, end,
            		$scope.currentPage, 
            		$scope.itempersize).then(function (dataResponse) {
            	$scope.lists = dataResponse.data['result'];
                $scope.totalItems = dataResponse.data['page'].totalRecord;
            });
        };
        
        $scope.search1();
        
      //点击导出触发
        $scope.export1 = function (currentPage) {
        	var begin = $("#beginDate").val(); 
        	var end = $("#endDate").val();
        	if(currentPage==null || currentPage==undefined || !currentPage){
        		statisticaorderService.export1($scope.sorder,begin,end, null ,null,false);
        	}else{
        		statisticaorderService.export1($scope.sorder,
            			begin,end,
                		$scope.currentPage, 
                		$scope.itempersize,true);
        	}
        };
        
        //点击导出触发
        $scope.export2 = function () {
        	var begin = $("#beginDate").val(); 
        	var end = $("#endDate").val();
        	statisticaorderService.export1($scope.sorder,
        			begin,end,
            		$scope.currentPage, 
            		$scope.itempersize,true);
        };

        //打开编辑页面
        $scope.edit = function (sorder) {
            var modalInstance = $modal.open({
                templateUrl: 'views/service/statisticaorder/edit.html',
                controller: 'sorderEditCtrl',
                resolve: {
                	'sorder': function () {  return angular.copy(sorder);   }
//                	'pq': function () {  return $scope.pageQuery;   }
//                	'modalInstance':function () {  return modalInstance;   }
                }
            });
            modalInstance.result.then(function () {
                $scope.search1();
            }, function () {
            });
        };
 }]);  



angular.module('sbAdminApp').controller('sorderEditCtrl', function ($scope,sorder, $modalInstance, statisticaorderService, $log, $location ) {
    $scope.sorder = sorder;
    //修改 
    $scope.edit = function () {
    	var sc=$scope.sorder;
    	var ss=sc.settlementSum;    
    	var ess=$scope.editsettlementSum;
    	//值没有变直接关闭弹框
    	if(ess=='' || ess==null || ess==undefined || ss==ess){
    		$modalInstance.close();
    	}else{  //修改了之后需要去数据库修改金额
    		statisticaorderService.edit1(sc.id,ess).then(function (dataResponse) {
    			//更新成功
    	        if(dataResponse.data['result']==1){
    	        	$modalInstance.close();
    	        }else{
    	        	alert("修改失败");
    	        }
            });
    	}
    };

    //关闭模态框
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
 
});
